<!-- 借款金额 -->
<template>
  <a-modal
    :maskClosable="false"
    title="借款明细"
    :width="1350"
    :bodyStyle="{
      padding: '0 24px'
    }"
    :visible="visible"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card
      :bordered="false"
      :bodyStyle="{
        padding: '10px 24px'
      }">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="handleQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="单据编号">
                <j-input placeholder="请输入单据编号" v-model="queryParam.billNo"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="申请人">
                <select-user-by-dep :multi="false" v-model="queryParam.proposer"/>
              </a-form-item>
            </a-col>
            <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handleQuery" icon="search">查询</a-button>
                <a-button @click="allSearchReset()" icon="reload" style="margin-left: 8px;">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- table区域-begin -->
      <div>

        <a-table
          ref="table"
          :scroll="{x:scrollX}"
          bordered
          rowKey="id"
          :columns="defColumns"
          :components="draggableComponent"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange">
          <template slot="status" slot-scope="status">
            <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
          </template>
          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img
              v-else
              :src="getImgView(text)"
              height="25px"
              alt=""
              style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
              下载
            </a-button>
          </template>
          <span slot="action" slot-scope="text, record">
            <a @click="onDetail(record)">详情</a>
          </span>

        </a-table>
      </div>
      <a-modal
        :maskClosable="false"
        title="借款信息"
        :width="1350"
        :bodyStyle="{
          padding: '0 24px'
        }"
        :visible="loanVisible"
        @cancel="handleLoanCancel"
        cancelText="关闭">
        <a-card
          :bordered="false"
          :bodyStyle="{
            padding: '10px 24px'
          }">
          <erp-finance-loan-bill-form ref="realForm" :disabled="true" :borrowMoneyFlag="true" normal></erp-finance-loan-bill-form>
        </a-card>
        
        <template slot="footer">
          <a-button @click.stop="()=>{loanVisible=false}">关闭</a-button>
        </template>
      </a-modal>
    </a-card>
    <template slot="footer">
      <a-button @click.stop="()=>{visible=false}">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import ErpFinanceLoanBillForm from '@/views/erp/finance/borrow/modules/ErpFinanceLoanBillForm'
import { getAction } from '@/api/manage';
import { DragResizable } from '@/mixins/DragResizable'
export default {
  name: 'ErpProjectFinanceLoanList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin,DragResizable],
  components: {
    SelectUserByDep,
    ErpFinanceLoanBillForm
  },
  data() {
    return {
      queryParam: {},
      projectId: '',
      visible: false,
      loanVisible: false, // 借款信息弹窗
      caId: 'undefined',
      description: '借款明细',
      // 表头
      columns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          align: 'center',
          key: 'rowIndex',
          // fixed: 'left',
          width: 70,
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'billNo',
          // fixed: 'left',
          width: 150,
          ellipsis: true
        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'proposerDeptId_dictText',
          width: 150,
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
          width: 100,
          ellipsis: true

        },
        
        {
          title: '借款金额(元)',
          align: 'center',
          dataIndex: 'amount',
          width: 100,
          ellipsis: true
        },
        {
          title: '借款方式',
          align: 'center',
          dataIndex: 'borrowMode_dictText',
          width: 100,
          ellipsis: true
        },
        {
          title: '借款说明',
          align: 'center',
          dataIndex: 'borrowExplain',
          width: 250,
          ellipsis: true
        },
        {
          title: '单据状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
          width: 100,
          scopedSlots: { customRender: 'bpmStatus' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 60,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/finance/borrow/erpFinanceLoanBill/normalList',
        queryById: '/api/erp/finance/borrow/erpFinanceLoanBill/queryById',
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    // 初始化字典配置 在自己页面定义
    this.initColumns()
    this.resetScreenSize();
    this.getSuperFieldList();
    this.customKey = 'defColumns'
    this.defColumnswidth = this.defColumns.map(val => {
      return val.width
    })
  },
  computed: {
  },
  methods: {
    async loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();// 查询条件
      params.projectId = this.projectId
      this.loading = true;
      let res = await getAction(this.url.list, params)
      this.loading = false;
      if (res.success) {
        this.dataSource = res.result ? res.result.records : []
        this.ipagination.total = res.result ? res.result.total : ''
        // 判断是否当前页没有数据且不为第一页
        if (this.dataSource.length == 0 && this.ipagination.current != 1) {
          this.ipagination.current = this.ipagination.current - 1
          this.loadData(this.ipagination.current - 1);
        }

        const data = [...this.dataSource];
        if (this.queryParam.bizTaskType == '1') {
          for (var i = 0; i < data.length; i++) {
            // item.taskUrge = false;
            var item = data[i];
            var params = { flowCode: this.flowCode, dataId: item.id };// 查询条件
            let res2 = await getAction(this.url.checkNotify, params);
            if (res2.result) {
              item.taskUrge = true;
            }
          }
        }
        this.dataSource = data;
      } else {
        this.$message.warning(res.message)
      }
      this.bizCount();
    },
    onDetail(record){
      let id = record.id
      getAction(this.url.queryById, { id }).then((res) => {
      if (res.success) {
        this.loanVisible = true
        this.$nextTick(() => {
          this.$refs.realForm.edit(res.result);
        })
      } else {
        this.$message.warning(res.message)
      }
    })
      
      // this.$refs.contractForm.initData(record.id);
      // this.$refs.contractForm.visible = true;
    },
    // 触发屏幕自适应
    resetScreenSize() {
      let screenWidth = document.body.clientWidth;
      if (screenWidth < 500) {
        this.scrollTrigger = { x: 800 };
      } else {
        this.scrollTrigger = {};
      }
    },
    handleCancel() {
      this.visible = false;
    },
    // 借款信息弹窗关闭
    handleLoanCancel () {
      this.loanVisible = false
    },
    allSearchReset() {
      this.queryParam = {};
      this.loadData(1);
    },
    initData(val) {
      this.caId = val
      this.allSearchReset()
      this[this.customKey].forEach((val,index) => {
        val.width = this[this.customKey+'width'][index]
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'htbh', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'htlx', text: '合同类型', dictCode: 'htlx_type' })
      fieldList.push({ type: 'string', value: 'htmc', text: '合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmmc', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmbh', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jytd', text: '经营团队', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yjgsnd', text: '业绩归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'string', value: 'qddw', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmcjr', text: '项目承接人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzdw', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxr', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxfs', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'date', value: 'qdrq', text: '签订日期' })
      fieldList.push({ type: 'int', value: 'sfyz', text: '是否用印', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'yzlx', text: '印章类型', dictCode: 'yzlx_type' })
      fieldList.push({ type: 'int', value: 'yyfs', text: '用印份数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'glskht', text: '关联收款合同', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'skhtmc', text: '收款合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jf', text: '甲方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yf', text: '乙方', dictCode: '' })
      fieldList.push({ type: 'int', value: 'skhte', text: '收款合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtedx', text: '收款合同额大写', dictCode: '' })
      fieldList.push({ type: 'int', value: 'bchte', text: '本次合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bchtedx', text: '本次合同额大写', dictCode: '' })
      fieldList.push({ type: 'date', value: 'fwqx', text: '服务期限' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '状态', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleQuery() {
      // this.queryParam.bchte_begin = this.queryParam.bchte_begin * 100
      // this.queryParam.bchte_end = this.queryParam.bchte_begin * 100
      this.searchQuery()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
